package com.rrd.dw.mr.gzip.kafka;

import java.io.IOException;
import java.util.Date;
import java.util.regex.Pattern;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import com.rrd.dw.utils.DateUtil;
import com.rrd.dw.utils.MD5Util;
import com.ucredit.babel.common.kafka.CrawlResult;
import com.ucredit.babel.common.model.Job;
import com.ucredit.babel.common.model.third.xinyan.XinyanData;
import com.ucredit.babel.common.model.third.xinyan.XinyanBlackRecord;

/**
 * 新颜负面洗白数据
 * @author zhangjunjian
 */
@Deprecated
public class XinyanBlackParse {
    public static final String CRT001 =  "\001";
    public static final Pattern CRT001_PATTERN =  Pattern.compile("\001");
    private String job_id ="";
    private String job_type ="black";
    private StringBuilder sb = new StringBuilder(500);
    private  Text val = new Text();
    private  Text key= new Text();
    /**
     * 新颜负面洗白数据
     * @param xinyanblackRecord
     * @throws InterruptedException
     * @throws IOException
     */
    public  void parseXINYANBLACK(Context context,XinyanBlackRecord xinyanblackRecord,String successful,String dataJson) throws IOException, InterruptedException{
        new StringBuilder(200);
        Job job = xinyanblackRecord.getJob();
        XinyanData data = xinyanblackRecord.getXinyanData();
        sb.delete(0,sb.length());
        //job_id
        this.job_id = job.getJobID()==null?"":job.getJobID();

        sb.append(job_id).append(CRT001);

        sb.append(job.getSystemID()==null?"":job.getSystemID()).append(CRT001);
        //响应http状态 "name", "certtype",  "reason", "createtype","data"
        sb.append(data.getName()==null?"":data.getName()).append(CRT001);
        //
        sb.append(data.getIdCardNo()==null?"":data.getIdCardNo()).append(CRT001);
        //
        sb.append(data.getMobile()==null?"":data.getMobile()).append(CRT001);
        //
        sb.append(data.getBankNo()==null?"":data.getBankNo()).append(CRT001);
        //
        sb.append(data.getVersion()==null?"":data.getVersion()).append(CRT001);
        //
        sb.append(data.getData()==null?"":data.getData()).append(CRT001);

        sb.append(job_type);
        key.set("xinyanblack_data");
        val.set(sb.toString().replace("\n", " "));
        context.write(key, val);
        sb.delete(0,sb.length());
        sb.append(job_id).append(CRT001).append(dataJson).append(CRT001).append(job.getSystemID()).append(CRT001).append(job_type);
        key.set("xinyanblack_datajson");
        val.set(sb.toString().replace("\n"," "));
        context.write(key, val);
    }


}
